
layui.config({
	base : "js/"
}).use(['form','layer'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		$ = layui.jquery;
	//video背景
	$(window).resize(function(){
		if($(".video-player").width() > $(window).width()){
			$(".video-player").css({"height":$(window).height(),"width":"auto","left":-($(".video-player").width()-$(window).width())/2});
		}else{
			$(".video-player").css({"width":$(window).width(),"height":"auto","left":-($(".video-player").width()-$(window).width())/2});
		}
	}).resize();


    //监听提交
    //监听提交
    form.on('submit(login)', function(data){
        var index = layer.msg('正在登录，请稍候',{icon: 16,time:20000,shade:0.8});
        setTimeout(function(){
            $.ajax({
                type: "post",
                url: ctx + "/service/admin/login.do",
                contentType: "application/json",
                async: false,
                data: JSON.stringify(data.field),
                success: function (data) {
                    layer.close(index);
                    console.log(data);
                    if (data.status == 0) {
                        console.log(data);
                        location.href = ctx + "/service/admin/index";
                    } else {
                        top.layer.msg(data.msg, {icon: 2});
                        RefreshCode();//刷新验证码
                    }
                },
            })
        },2000);
        return false;
    });


    //点击刷新验证码
    $(".code").click(function(){
        RefreshCode(); //刷新验证码
    });

    //刷新验证码
    function RefreshCode(){
        var codeImg = $("#codeImg");
        var src = codeImg.attr("src");
        codeImg.attr("src",chgUrl(src));
    }
    //为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
    function chgUrl(url){
        var timestamp = (new Date()).valueOf();
        url = url.substring(0,13);
        if((url.indexOf("&")>=0)){
            url = url + "×tamp=" + timestamp;
        }else{
            url = url + "?timestamp=" + timestamp;
        }
        return url;
    }
})

